package com.company.thread;

/**
 * @description: some desc
 * @author: ruoan
 * @date: 2020/10/23 16:06
 */
public class MyThread10 {


    public static void main(String[] args) {

        Thread t  = new Thread(new OtherRunnableObj2());
        t.setName("我是t");
        t.start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main 让线程“我是t” wait  ");
        try {
            t.wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("main exit");

    }
}
class OtherRunnableObj2 implements Runnable {
    @Override
    public void run() {
        try {
            System.out.println(Thread.currentThread().getName()+"进入睡眠");
            for (int i = 1; i < 10000; i++) {
                System.out.println("i:"+i);
                Thread.sleep(500);
            }
        } catch (InterruptedException e) {
            System.out.println(Thread.currentThread().getName()+"退出睡眠");
            //e.printStackTrace();
        }
    }
}